package com.chen.pspms.service.impl;

import com.chen.pspms.entity.Majorhazardregistertable;
import com.chen.pspms.entity.Resource;
import com.chen.pspms.entity.Resourcedemand;
import com.chen.pspms.entity.Standardizationtable;
import com.chen.pspms.mapper.ResourcedemandMapper;
import com.chen.pspms.mapper.StandardizationMapper;
import com.chen.pspms.service.ResourceService;
import com.chen.pspms.utils.ApplicationException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service
public class ResourceServiceImpl implements ResourceService {
    @Autowired
    ResourcedemandMapper resourcedemandMapper;

    @Override
    public Resource geResource(Majorhazardregistertable majorhazardregistertable) throws ApplicationException {
        if(majorhazardregistertable==null) return null;
        Standardizationtable standardizationtable=majorhazardregistertable.getStandardizationtable();
        String level=majorhazardregistertable.getLevel();
        Resourcedemand resourcedemand=resourcedemandMapper.findyByType(standardizationtable.getHazardtype());
        String need=null;
        switch (level){
            case "预警":need=resourcedemand.getWarning();break;
            case "一级":need=resourcedemand.getLevel1();break;
            case "二级":need=resourcedemand.getLevel2();break;
            case "三级":need=resourcedemand.getLevel3();break;
        }
        return new Resource(standardizationtable,level,need);
    }

    @Override
    public List<Resource> geResourceList(List<Majorhazardregistertable> majorhazardregisterList) throws ApplicationException {
        List<Resource> resourceList=new ArrayList<>();
        for(Majorhazardregistertable majorhazardregistertable:majorhazardregisterList){
            resourceList.add(geResource(majorhazardregistertable));
        }
        return resourceList;
    }
}
